package com.exercises;

import java.util.Arrays;

class Exercise1833 {
    public static void main(String[] args) {
        System.out.println(maxIceCream(new int[]{1, 6, 3, 1, 2, 5}, 20));
    }

    public static int maxIceCream(int[] costs, int coins) {
        Arrays.sort(costs);
        int count = 0;
        for (int c : costs) {
            if (coins >= c) {
                coins -= c;
                count++;
            } else {
                break;
            }
        }
        return count;
    }
}

